package view;

import helper.ButtonListener;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.SystemColor;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;

public class MainMenu extends JFrame {

	private Properties systemProperties = new Properties();
	private int width;
	private int heigth;
	private JPanel menuPanel = new JPanel();
	private JPanel ingamePanel = new JPanel();
	private JPanel summaryPanel = new JPanel();
	private Board board;
	private JButton btn_start = new JButton("Start Game");
	private JButton btn_options = new JButton("Options");
	private JButton btn_exit = new JButton("Exit");
	private final JLabel lblDinerKing = new JLabel("Diner King");
	private JButton btn_NextRound = new JButton("Next Round");
	private JSeparator separator = new JSeparator();
	private JSeparator separator_1 = new JSeparator();
	private JLabel lbl_Ausgaben = new JLabel("Ausgaben");
	private JLabel lbl_Einnahmen = new JLabel("Einnahmen");
	private JSeparator separator_2 = new JSeparator();
	private JSeparator separator_3 = new JSeparator();
	private JLabel lbl_Zusammenfassung = new JLabel("Tagesbilanz");
	private JLabel lbl_Warenverkauf = new JLabel("Warenverkauf :");
	private JLabel lbl_Wareneinkauf = new JLabel("Wareneinkauf :");
	private JLabel lbl_outgoing = new JLabel();
	private JLabel lbl_incoming = new JLabel();
	private final String MENUPANEL ="Panel for main menu";
	private final String INGAMEPANEL = "Panel for not visible ingame buttons";
	private final String BOARD = "Board with ingame Buttons and grafics";
	private final String SUMMARYPANEL = "Panel for round summary";
	private CardLayout mainLayout = new CardLayout();

	public MainMenu() {
		try {
			systemProperties.load(new FileInputStream(new File("sources/properties/system.properties")));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
		} catch (IOException e) {
			// TODO Auto-generated catch block
		}
		
		width = Integer.parseInt(systemProperties.getProperty("FrameWidth"));
		heigth = Integer.parseInt(systemProperties.getProperty("FrameHeigth"));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(width, heigth);
		setLocationRelativeTo(null);
		setTitle(systemProperties.getProperty("Name"));
		getContentPane().setLayout(mainLayout);
		setResizable(false);
		setVisible(true);

		board = new Board(this);
		buildMenuPanel();

		getContentPane().add(board,BOARD);
		getContentPane().add(menuPanel, MENUPANEL);
		getContentPane().add(summaryPanel, SUMMARYPANEL);
		mainLayout.show(getContentPane(), MENUPANEL);

	}

	public void buildSummaryPanel() {
		summaryPanel.setLayout(null);
	
		btn_NextRound.setBounds(275, 538, 109, 23);
		summaryPanel.add(btn_NextRound);
		
		separator.setBounds(0, 520, 394, 2);
		summaryPanel.add(separator);
		
		separator_1.setBounds(0, 53, 394, 2);
		summaryPanel.add(separator_1);
		
		lbl_Ausgaben.setFont(new Font("Arial", Font.PLAIN, 18));
		lbl_Ausgaben.setHorizontalAlignment(SwingConstants.CENTER);
		lbl_Ausgaben.setBounds(36, 77, 100, 22);
		summaryPanel.add(lbl_Ausgaben);
		
		lbl_Einnahmen.setHorizontalAlignment(SwingConstants.CENTER);
		lbl_Einnahmen.setFont(new Font("Arial", Font.PLAIN, 18));
		lbl_Einnahmen.setBounds(244, 77, 100, 22);
		summaryPanel.add(lbl_Einnahmen);
		
		separator_2.setOrientation(SwingConstants.VERTICAL);
		separator_2.setBounds(190, 54, 2, 468);
		summaryPanel.add(separator_2);

		separator_3.setBounds(0, 121, 394, 2);
		summaryPanel.add(separator_3);
		
		lbl_Zusammenfassung.setHorizontalAlignment(SwingConstants.CENTER);
		lbl_Zusammenfassung.setFont(new Font("Stencil", Font.BOLD | Font.ITALIC, 20));
		lbl_Zusammenfassung.setBounds(61, 11, 266, 31);
		summaryPanel.add(lbl_Zusammenfassung);
		
		lbl_Warenverkauf.setBounds(202, 150, 90, 23);
		summaryPanel.add(lbl_Warenverkauf);

		lbl_Wareneinkauf.setForeground(Color.BLACK);
		lbl_Wareneinkauf.setBounds(10, 150, 90, 23);
		summaryPanel.add(lbl_Wareneinkauf);

		lbl_outgoing.setHorizontalAlignment(SwingConstants.CENTER);
		lbl_outgoing.setBounds(128, 150, 52, 23);
		lbl_outgoing.setText(board.getShop().getRoundOutgoingCash()+" $");
		summaryPanel.add(lbl_outgoing);

		lbl_incoming.setHorizontalAlignment(SwingConstants.CENTER);
		lbl_incoming.setBounds(332, 150, 52, 23);
		lbl_incoming.setText(board.getShop().getRoundIncomingCash()+" $");
		summaryPanel.add(lbl_incoming);
		btn_NextRound.addActionListener(new ButtonListener(this));
		
	}

	private void buildMenuPanel() {
		menuPanel.setLayout(null);
		menuPanel.setBackground(SystemColor.activeCaption);
		lblDinerKing.setFont(new Font("Agency FB", Font.BOLD, 40));
		lblDinerKing.setBounds(116, 51, 158, 71);
		menuPanel.add(lblDinerKing);
		
		lblDinerKing.setHorizontalAlignment(SwingConstants.CENTER);
		btn_start.setBounds(142, 173, 104, 23);
		menuPanel.add(btn_start);
		
		btn_options.setBounds(142, 239, 104, 23);
		menuPanel.add(btn_options);
		btn_exit.setBounds(142, 309, 104, 23);
		menuPanel.add(btn_exit);
		
		btn_exit.addActionListener(new ButtonListener(this));
		btn_options.addActionListener(new ButtonListener(this));
		btn_start.addActionListener(new ButtonListener(this));
		
	}

	public static void main(String[] args) throws FileNotFoundException, IOException {
		new MainMenu();

	}

	public JPanel getMenuPanel() {
		return menuPanel;
	}

	public JPanel getIngamePanel() {
		return ingamePanel;
	}

	public Board getBoard() {
		return board;
	}

	public void setBoard(Board board) {
		this.board = board;
	}

	public JButton getBtn_start() {
		return btn_start;
	}

	public JButton getBtn_options() {
		return btn_options;
	}

	public JButton getBtn_exit() {
		return btn_exit;
	}

	public JLabel getLblDinerKing() {
		return lblDinerKing;
	}

	public JPanel getSummaryPanel() {
		return summaryPanel;
	}

	public JButton getBtn_NextRound() {
		return btn_NextRound;
	}

	public String getMENUPANEL() {
		return MENUPANEL;
	}

	public String getINGAMEPANEL() {
		return INGAMEPANEL;
	}

	public String getBOARD() {
		return BOARD;
	}

	public String getSUMMARYPANEL() {
		return SUMMARYPANEL;
	}

	public CardLayout getMainLayout() {
		return mainLayout;
	}
	
}
